<?php
/**
 * Math
 *
 * Math related handler, considering to using BC as underlying processor.
 *
 * @author  Badrus Said <badrus.said@gmail.com>
 * @since   gop1.0
 */
final class gop_Math extends gop_Base {
    public function execute(gop_Base $_caller = null) {
        if ($this->getReturn()) return;
        $this->setCaller($_caller);
        $_return = null;
        $G1 = $this->getContext()->getCallee($this->Left)->execute($this);
        $G2 = $this->getContext()->getCallee($this->Right)->execute($this);
        if (!(is_numeric($G1) && is_numeric($G2))) {
            throw new Exception("MathException: G1 and G2 must be numeric.");
        }
        switch($this->Operator) {
            case "+": $_return = $G1 + $G2; break;
            case "-": $_return = $G1 - $G2; break;
            case "*": $_return = $G1 * $G2; break;
            case "/": $_return = $G1 / $G2; break;
            case "%": $_return = $G1 % $G2; break;
        }
        $this->setResult($_return);
        $this->chainExec();
    }
}
?>